package com.adrian.controller;

import com.adrian.pojo.Product;
import com.adrian.pojo.Type;
import com.adrian.service.ProductService;
import com.adrian.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: Adrian
 * @Date: 2020/3/20 19:04
 * @Description:
 */
@RestController
public class ProductController {

    @Autowired
    private ProductService productService;
    @Autowired
    private ProductTypeService productTypeService;

    /**
     * 01-查询
     * @return
     */
    @RequestMapping("/product_list")
    public List<Product> getList(){
        return productService.getProducts();
    }

    /**
     * 02-新增
     * @param product
     * @return
     */
    @RequestMapping("/product_addProduct")
    public int addProduct(@RequestBody Product product){
        return productService.addPrdouct(product);
    }

    /**
     * 加载所有的类别下拉框数据
     * @return
     */
    @RequestMapping("/product_types")
    public List<Type> getTypes(){
        return productTypeService.getTypes();
    }

    /**
     * 根据ID查询对象
     * @param id
     * @return
     */
    @RequestMapping("/product_getById")
    public Product getById(@RequestParam int id){
        return productService.getById(id);
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @RequestMapping("/product_delete")
    public int deleteProduct(@RequestParam int id){
        return productService.deleteProduct(id);
    }

    /**
     * 根据ID更新
     * @param product
     * @return
     */
    @RequestMapping("/product_updatebyId")
    public int updateProduct(@RequestBody Product product){
        return productService.updateById(product);
    }
}
